library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.4 ✓ dplyr 1.0.7
## ✓ tidyr 1.1.3 ✓ stringr 1.4.0
## ✓ readr 2.0.1 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(p8105.datasets)
library(dplyr)
library(tidyr)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(ggridges)
library(httr)
##
## Attaching package: 'httr'
## The following object is masked from 'package:plotly':
##
## config
library(jsonlite)
##
## Attaching package: 'jsonlite'
## The following object is masked from 'package:purrr':
##
## flatten
library(flexdashboard)
Column
Chart A
data("instacart")
instacart_department =
count(instacart, department) %>%
arrange(n) %>%
mutate(
department = factor(department, levels = department)
)
instacart_department %>%
plot_ly(x = ~n, y = ~department, color = ~department, type = "bar", colors = "viridis")
Column
Chart B
instacart_aisle = count(instacart, aisle) %>%
filter(n > 10000) %>%
arrange(n) %>%
mutate(
aisle = factor(aisle, levels = aisle)
)
instacart_aisle %>%
plot_ly(x = ~n, y = ~aisle, color = ~aisle, alpha = .5,
type = "scatter", mode = "markers"
)
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
Chart C
data("instacart")
instacart_3 = instacart %>%
filter( days_since_prior_order <= 10) %>%
mutate(department = str_to_title(department)) %>%
mutate(
department = fct_infreq(department),
department = fct_recode(department)) %>%
select(department, order_number)
instacart_3 %>%
plot_ly(
x = ~department, y = ~order_number, color = ~department,
type = "box", colors = "viridis"
)
# instacart_3 = instacart %>%
# filter( aisle == "baking ingredients" | aisle == "dog food care" | aisle == "packaged vegetables fruits") %>%
# select(aisle, department, order_number)
#
#
# instacart_3 %>%
# plot_ly(
# x = ~aisle, y = ~order_number, color = ~department,
# type = "box", colors = "viridis"
# )